package com.dabai.simpleconnection.activitys;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.dabai.dbutils.data.Patterns;
import com.dabai.dbutils.dialog.MdcDialog;
import com.dabai.dbutils.utils.DabaiUtils;
import com.dabai.dbutils.utils.StringUtils;
import com.dabai.simpleconnection.MainActivity;

import java.util.regex.Matcher;

/**
 * Description : Other
 *
 * @author BAI
 */
public class SendLink extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Intent intent = getIntent();
        try {

            if (intent == null)
                return;
            Bundle extras = intent.getExtras();
            if (extras == null)
                return;

            if ("text/plain".equals(intent.getType())) {//分享的内容类型，如果png图片：image/png

                String content = "" + extras.get(Intent.EXTRA_TEXT);

                Matcher matcher = Patterns.WEB_URL.matcher(content);
                if (matcher.find()) {
                    content = matcher.group();

                    Intent msg = new Intent(this, MainActivity.class);
                    intent.putExtra("link", content);
                    setResult(301,msg);
                    finish();

                }

            }

        } catch (Exception e) {
            DabaiUtils.showToast(this, "异常:" + e.getMessage());
            Log.d("DBTAG", "onCreate: " + e.getMessage());
            DabaiUtils.backHome(this);
            finish();
        }

    }
}
